# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Timothy Redaelli <timothy.redaelli@gmail.com>
# Contributor: Bartlomiej Piotrowski <nospam@bpiotrowski.pl>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Jason Pierce <pierce.json@gmail.com>
# Contributor: Jeremy Cowgar <jeremy@cowgar.com>
# Contributor: Simon Perry <aur@sanxion.net>

pkgbase=dropbear
pkgname=(dropbear dropbear-scp)
pkgver=2022.83
pkgrel=1
pkgdesc='Lightweight SSH server'
arch=(loong64 x86_64)
url='https://github.com/mkj/dropbear'
license=(MIT)
options=(emptydirs)
makedepends=(git)
validpgpkeys=('F7347EF2EE2E07A267628CA944931494F29C6773')
source=("git+$url#commit=a4689e25ec85904b9111f4e96d3994ff17b1c3e6" # tag: DROPBEAR_2022.83
        dropbear.service
        localoptions.h)
b2sums=('SKIP'
        'e3481447cac72e416a1d332ddb4bc2fbc78b2e558f929449469e05c269e27482e13357d467b8a11c9b7bf6fdecdd6e57717c8008247922adfc545c36e5775217'
        '49628bbce0d26eb33598de276ede705bd592a38b7892c9db0ceebfb0598a1ee6e7e84ed03dbf255ee1adcad0c5214d38dc03e6c04176a405f59a19765cb28388')

prepare() {
  cp -fv localoptions.h $pkgname/localoptions.h
}

build() {
  cd $pkgname
  autoconf
  autoheader
  ./configure --bindir=/usr/bin --prefix=/usr --sbindir=/usr/bin
  make \
    PROGRAMS='dbclient dropbear dropbearconvert dropbearkey scp' \
    SCPPROGRESS=1
}

package_dropbear() {
  depends=(libxcrypt zlib)
  install -d "$pkgdir/etc/$pkgname"
  make -C $pkgbase install DESTDIR="$pkgdir"
  install -Dm644 $pkgname.service \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -Dm644 $pkgbase/LICENSE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_dropbear-scp() {
  pkgdesc='Lightweight application for copying files over SSH'
  provides=(scp)
  conflicts=(openssh)
  make -C $pkgbase install PROGRAMS=scp DESTDIR="$pkgdir"
  install -Dm644 $pkgbase/LICENSE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  rmdir "$pkgdir/usr/share/man/"{man1,}
}
